﻿using System;
using System.Web.UI.WebControls;
using BIS.Portal.Core.Base;
using BIS.Portal.Core.Global;
using BIS.Utility.Converter;
using BIS.Portal.Modules.CMS.BO;
using BIS.Portal.Modules.CMS.Entity;


namespace BIS.Portal.Modules.CMS
{
    public partial class CmsArticleDetail : ControlBase
    {
        #region Get data settings

        public bool HienThiAnhMinhHoa
        {
            get
            {
                return GetControlSetting<bool>(ModuleSettingNames.CmsArticleDetail.ddlAnhMinhHoa,
                                               PortalContext.LanguageAlias);
            }
        }
        public bool HienThiTieuDe
        {
            get
            {
                return GetControlSetting<bool>(ModuleSettingNames.CmsArticleDetail.ddlTieuDe,
                                               PortalContext.LanguageAlias);
            }
        }
        public bool HienThiMoTa
        {
            get
            {
                return GetControlSetting<bool>(ModuleSettingNames.CmsArticleDetail.ddlMoTa,
                                               PortalContext.LanguageAlias);
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            loadData();
        }
        private void loadData()
        {
            if (Request[ModuleQueryStringKey.ArticleId] != null)
            {
                int _ArticleId = Functions.GetInt(Request[ModuleQueryStringKey.ArticleId]);
                ClientCmsArticleDetailsEntity objArticle =
                    ClientCmsArticleBO.GetArticleByArticleId(PortalContext.LanguageInUseId, _ArticleId);
                if (HienThiAnhMinhHoa)
                {
                    Anh_Minh_Hoa.ImageUrl = objArticle.ThumbImage;
                    Anh_Minh_Hoa.AlternateText = objArticle.ArticleTitle;
                    Anh_Minh_Hoa.Attributes.Add("onerror", "ImageNotFound(this);");
                }
                if (HienThiTieuDe)
                {
                    Tieu_De.Text = objArticle.ArticleTitle;
                }
                if (HienThiMoTa)
                {
                    //Literal ltrMo_ta = this.Page.FindControl("Mo_ta") as Literal;
                    //if (ltrMo_ta != null) 
                    Mo_ta.Text = objArticle.ArticleDescription;
                }
                Chi_Tiet_Noi_Dung.Text = objArticle.ArticleContent;
                Ten_Nhom_tin.Text = objArticle.CategoryName;
                #region Url Nhóm tin
                string urlNhomTin = WebHelpers.GetLink(ModuleQueryStringKey.UrlNhomTin, objArticle.PageAlias,
                                    new string[]
                                            {
                                           ModuleQueryStringKey.CategoryId,
                                           ModuleQueryStringKey.CategoryName,
                                           },
                                    new string[]
                                            {
                                           Convert.ToString(objArticle.CategoryId),
                                           Functions.UnicodeToKoDauAndGach(objArticle.CategoryName)
                                           }
                );

                #endregion

                Ten_Nhom_tin.NavigateUrl = urlNhomTin;
            }
        }
    }
}